//
//  ViewController.m
//  MXLoginMethodsDomo
//
//  Created by 马彦 on 16/9/26.
//  Copyright © 2016年 MX. All rights reserved.
//
/**
  MXLockPassword 类 
 密码的存储和提取类
 
 */

#import "ViewController.h"
#import "MXLoginSettingTableViewCell.h"
#import "UITableViewCell+Cellutils.h"
/**手势密码*/
#import "MXGesturesViewController.h"
#import "MXLockPassword.h"
#import "MXLockViewController.h"

/**指纹密码*/
#import "MXFingerprintVC.h"
#import "MXTouchIDPassword.h"
#import "WJTouchID.h"

#import "MXFaceRecgnitionVC.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSArray *mainStrArray;
@property (nonatomic, strong) NSArray *stateStrArray;

@end

@implementation ViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.tableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    self.mainStrArray = @[@"手势密码",@"指纹密码",@"脸部识别密码"];
    self.stateStrArray = @[@"关",@"关",@"关"];
    [self.view addSubview:self.tableView];
    
}

#pragma mark - UITableViewDataSource 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.mainStrArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MXLoginSettingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[MXLoginSettingTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if (indexPath.row == 0) {
        if ([MXLockPassword isEmptyPassword]) {
            cell.stateStr = self.stateStrArray[indexPath.row];
        } else {
            cell.stateStr = @"开";
        }
        
    } else if (indexPath.row == 1) {
        if ([MXTouchIDPassword isEmptyPassword]) {
            cell.stateStr = self.stateStrArray[indexPath.row];
        } else {
            cell.stateStr = @"开";
        }
    } else  {
        cell.stateStr = self.stateStrArray[indexPath.row];
    }
    cell.mainStr = self.mainStrArray[indexPath.row];
    
    [cell addBottomHorizontalLine:5];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 15;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return CellHeight;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc] init];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.row == 0) {
        MXGesturesViewController *gesturesVC = [[MXGesturesViewController alloc] init];
        [self.navigationController pushViewController:gesturesVC animated:YES];
        
    } else if (1 == indexPath.row) {
        MXFingerprintVC *fingerprintVC = [[MXFingerprintVC alloc] init];
        [self.navigationController pushViewController:fingerprintVC animated:YES];
    } else if (2 == indexPath.row) {
        MXFaceRecgnitionVC *faceVC = [[MXFaceRecgnitionVC alloc] init];
        [self.navigationController pushViewController:faceVC animated:YES];
    }
}

#pragma mark -lazy

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = RGBA_Color(0.97, 0.97, 0.97, 1.0);
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
